#include "mod.h"

MOD * modinit(INFO *info) {

   MOD *mod;
   char name[50];
   int i;

   mod = (MOD *) calloc(0,sizeof(MOD));
   info->mods=0;

   for(i=0;strlen(info->modules[i])>0;i++) {

      mod = (MOD *) realloc(mod, (i+1)*sizeof(MOD));
      sprintf(name, "./mods/%s.so", info->modules[i]);
      mod[i].dl = dlopen(name,RTLD_LAZY);
      if (mod[i].dl) {
         mod[i].init = dlsym(mod[i].dl,"onebot_m");
         info->mods++;
      }

   }

   return mod;

}

void modend(INFO *info, MOD *mod) {

   int i;

   for(i=0;i<info->mods;i++)
      if(mod[i].dl) dlclose(mod[i].dl);

   return;

}
